import random
import pygame
import sys
import time
from pygame.locals import *


POINT_UP=1
POINT_DOWN=2
POINT_RIGHT=3
POINT_LEFT=4

class Point:
    x = None
    y = None
    dir = None
    x2 = None
    y2 = None
    dir2 = random.randint(1, 4)
    
    def move_down(self, distance ):
        self.y = self.y + distance
    
    def move_up(self, distance):
        self.y = self.y - distance
        
    def move_right(self, distance):
        self.x = self.x + distance
        
    def move_left(self, distance):
        self.x = self.x - distance
        
    def change_dir(self, direction ):
        
        
        if direction == K_UP:
            self.dir = POINT_UP
        if direction == K_DOWN:
            self.dir = POINT_DOWN
        if direction == K_LEFT:
            self.dir = POINT_LEFT
        if direction == K_RIGHT:
            self.dir = POINT_RIGHT               

        
    def move_down2(self, distance2 ):
        self.y = self.y + distance2
    
    def move_up2(self, distance2):
        self.y = self.y - distance2
        
    def move_right2(self, distance2):
        self.x = self.x + distance2
        
    def move_left2(self, distance2):
        self.x = self.x - distance2
        
    def change_dir2(self, direction2 ):
        
        
        if direction2 == K_UP:
            self.dir = POINT_UP
        if direction2 == K_DOWN:
            self.dir = POINT_DOWN
        if direction2 == K_LEFT:
            self.dir = POINT_LEFT
        if direction2 == K_RIGHT:
            self.dir = POINT_RIGHT               

        
        
    def move(self, distance):
        if ( self.dir == POINT_UP ):
            self.move_up(distance)
        if ( self.dir == POINT_DOWN ):
            self.move_down(distance)
        if ( self.dir == POINT_RIGHT):
            self.move_right(distance)
        if ( self.dir == POINT_LEFT):
            self.move_left(distance)
            
    def move2(self, distance2):
        if ( self.dir2 == 1 ):
            self.move_up2(distance2)
        if ( self.dir2 == 2 ):
            self.move_down2(distance2)
        if ( self.dir2 == 3):
            self.move_right2(distance2)
        if ( self.dir2 == 4):
            self.move_left2(distance2)
    
    
 
pygame.init()
pygame.display.set_caption('Paint')
# screen = pygame.display.set_mode( (800,400), pygame.FULLSCREEN )
screen = pygame.display.set_mode( (800,400) )
screen.fill((125,0,125))




point_list = [point.x,p.y]
def refresh( points ):
    pygame.draw.lines( screen, (255,255,255), False, points )
    pygame.display.update()

def to_pairs( input ):
    output = []
    for i in input:
        output.append((i.x, i.y))
    return output


while True:
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                sys.exit()
            if ( head.change_dir( event.key ) ):
                old_head = head
                head = Point()
                head.x = old_head.x
                head.y = old_head.y
                head.dir = old_head.dir                
                point_list.append( head )
                            
    time.sleep(0.02)
    head.move(1)
    refresh( to_pairs(point_list) )
        
        
        